package com.tich.user.controller;

import com.tich.api.domain.dto.BalanceDeductDTO;
import com.tich.constant.ResponseMessageConstant;
import com.tich.result.Result;
import com.tich.user.domain.entity.User;
import com.tich.user.service.ClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/client")
@RestController
public class ClientController {

    @Autowired
    private ClientService clientService;

    /**
     * 扣除用户余额
     * @param balanceDeductDTO
     * @return
     * */
    @PostMapping("/balance/deduct")
    public Result<Boolean> balanceDeduct(@RequestBody BalanceDeductDTO balanceDeductDTO){
        log.info("扣除用户的余额:{}", balanceDeductDTO);
        return Result.success(ResponseMessageConstant.DEDUCT_SUCCESS,
                clientService.balanceDeduct(balanceDeductDTO));
    }

    @GetMapping("/user")
    public User getById(@RequestParam("userId") Long id){
        return clientService.getById(id);
    }
}
